package com.yijinsuo.activity;

import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.yijinsuo.R;
import com.yijinsuo.base.BaseActivity;
import com.yijinsuo.view.TitleBar;

import butterknife.Bind;
import butterknife.ButterKnife;

public class BannerWebViewActivity extends BaseActivity {
    @Bind(R.id.pb_loading)
    ProgressBar pbLoading;
    @Bind(R.id.mWebView)
    WebView vWVContent;
    @Bind(R.id.titlebar)
    TitleBar titleBar;
    //
    private  String url;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_banner_web_view);
        url=getIntent().getStringExtra("url");
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {

        titleBar.setTitleBar(R.drawable.back_selector, "", 0);
        titleBar.setTitleBarBackgroundColor(getResources().getColor(R.color.tou_ming));
        titleBar.setTitleBarLeftListener(this);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void setData() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            vWVContent.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        vWVContent.setWebViewClient(new WebViewClient());
        vWVContent.getSettings().setJavaScriptEnabled(true);
        vWVContent.getSettings().setBuiltInZoomControls(true); //显示放大缩小 controler
        vWVContent.getSettings().setSupportZoom(true); //可以缩放
        //屏幕自适应
        vWVContent.getSettings().setUseWideViewPort(true);
        vWVContent.getSettings().setLoadWithOverviewMode(true);

        vWVContent.setWebChromeClient(new WebChromeClient() {

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
// TODO Auto-generated method stub
                super.onProgressChanged(view, newProgress);
                pbLoading.setProgress(newProgress);
                if (newProgress == 100) {
                    pbLoading.setVisibility(View.GONE);
                }
            }
        });

       vWVContent.loadUrl(url);
    }


    @Override
    protected void widgetClick(View view) {

        switch (view.getId()){

            case R.id.titlebar_iv_back:

                finish();
                break;



            default:
        }
    }
}
